import pymysql
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from dbdatase import db1
driver=webdriver.Edge()
driver.get('http://10.59.9.12:7001/')
# 连接数据库
ls=db1(host='10.59.9.12',user='root',password='yidong666',databases='a3mall')
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(3)
dy1=driver.find_element(By.CLASS_NAME,'reg-new').text
print(dy1)
driver.find_element(By.NAME,'username').send_keys("13811033962")
time.sleep(3)
driver.find_element(By.NAME,'password').send_keys("123456")
time.sleep(15)
driver.find_element(By.CLASS_NAME,'finish-btn').click()
time.sleep(5)
dy2=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').text
print(dy2)
# 数据库断言
dy=ls.select("select username from mall_users where nickname='大帝'")[0]
assert "欢迎回来，" + dy[0]==dy2
time.sleep(2)
dy3=driver.find_element(By.CLASS_NAME,'color-black').text
dy31=dy3.replace('¥ ','')
print(dy31)
time.sleep(3)
dy4=driver.find_element(By.CLASS_NAME,'color-orage').text
print(dy4)
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(3)
driver.find_element(By.CLASS_NAME,'search-input').send_keys("宋牌电水壶")
time.sleep(3)
driver.find_element(By.CLASS_NAME,'search-input-btn').click()
time.sleep(3)
dy5=driver.find_element(By.XPATH,'/html/body/div[4]/a[2]').text
print(dy5)
driver.find_element(By.XPATH,'//img[@src="/uploads/images/20250620/67e1bd127f10d17039e45464df4c460a.jpg"]').click()
time.sleep(3)
dy6=driver.find_element(By.XPATH,'/html/body/div[4]/a[4]').text
print(dy6)
dy7=driver.find_element(By.ID,'sell-price-box').text
print(dy7)
num=driver.find_element(By.ID,'store_nums')
num.clear()
time.sleep(3)
num.send_keys('3')
time.sleep(3)
dy8=num.text
print(dy8)
driver.find_element(By.ID,'add-cart').click()
time.sleep(3)
driver.find_element(By.CLASS_NAME,'nav-settcart').click()
time.sleep(3)
driver.find_element(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[2]/td[1]/input').click()
time.sleep(3)
dy9=driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
print(dy9)
driver.find_element(By.CLASS_NAME,'ask-btn').click()
time.sleep(3)


